﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using fingerWinForm.Excel;
using System.IO;
using fingerWinForm.UpdrsTests;
using System.Windows.Forms;

namespace fingerWinForm.Algorithms.SVM
{
    
    class VectorOperations
    {
        public const int featureNumber = 11;
        public const int fingerTaps_featureNumber = 7;
        public const int HandMovements_featureNumber = 6;
        public static int numOfClasses ;

        static public void intArrayInit(ref int[] array)
        {
            for (int i = 0; i < numOfClasses; i++)
            {
                array[i]=0;
            }
        }

        static public void dupArrayInit(ref string[] array)
        {
            for (int i = 0; i < numOfClasses; i++)
            {
                array[i] = null;
            }
        }
        static public void scaleAraysInit(ref objForgenerateRandomVectorFile obj)
        {
            obj.index = 0;
            obj.fingerMaxArray = new float[fingerTaps_featureNumber];
            obj.fingerMinArray = new float[fingerTaps_featureNumber];
            obj.handMaxArray = new float[HandMovements_featureNumber];
            obj.handMinArray = new float[HandMovements_featureNumber];

            for (int i = 0; i < fingerTaps_featureNumber; i++)
            {
                obj.fingerMaxArray[i] = -255;
                obj.fingerMinArray[i] = 255;

            }
            for (int i = 0; i < HandMovements_featureNumber; i++)
            {
                obj.handMaxArray[i] = -255;
                obj.handMinArray[i] = 255;
            }
        }
        static public void OverSampligAddVectorsToPredictAndTrainFiles(ref int[] classcounterArray, ref string[] vectorsfordup, string filename, string testName)
        {
            int max = 0;
            string FilePath = @"C:\parkinsonTool\svm\" + testName;
            string[] subfilesNamesArry = System.IO.Directory.GetFiles(FilePath, "*.text"); //get all the names of the text files


            int[] fileclassCountArray = new int[numOfClasses];
            for (int i = 0; i < numOfClasses; i++)
            {
                fileclassCountArray[i] = 0;
            }

            string[] subvalues;

            for (int i = 0; i < classcounterArray.Length; i++)
            {
                if (max < classcounterArray[i])
                    max = classcounterArray[i];
            }

            foreach (string iterator_filename in subfilesNamesArry)
            {
                subvalues = iterator_filename.Split('\\');
                if (subvalues[4][0] == 't') //train file
                {
                    findOutclassesForThisFile(iterator_filename, ref fileclassCountArray, max);
                    overSamplingForThisFile(iterator_filename, ref fileclassCountArray, ref vectorsfordup);

                    for (int j = 0; j < numOfClasses; j++)
                    {
                        fileclassCountArray[j] = 0;
                    }
                }
            }
        }
        //find the amount of classes for each class
        static public void findOutclassesForThisFile(string filePath, ref int[] fileclassCountArray, int max)
        {
            string[] lines = System.IO.File.ReadAllLines(filePath);
            string[] values;

            for (int i = 0; i < lines.Count(); i++)
            {
                values = lines[i].Split(' ');
                if (numOfClasses == 3)
                {
                    switch (Convert.ToInt32(values[0]))
                    {
                        case 0:
                            fileclassCountArray[0]++;
                            break;
                        case 1:
                            fileclassCountArray[1]++;
                            break;
                        case 3:
                            fileclassCountArray[2]++;
                            break;
                    }
                }
                else
                {
                    fileclassCountArray[Convert.ToInt32(values[0])]++;
                }
            }
            for (int j = 0; j < numOfClasses; j++)
            {
                fileclassCountArray[j] = max - fileclassCountArray[j];
            }

        }
        static public void overSamplingForThisFile(string filePath, ref int[] fileclassCountArray, ref string[] vectorsfordup)
        {
            StreamWriter sw1;
            int i = 0;
            sw1 = new StreamWriter(filePath, true);

            for (i = 0; i < fileclassCountArray.Count(); i++)
            {
                for (int j = 0; j < fileclassCountArray[i]; j++)
                {
                    sw1.WriteLine(vectorsfordup[i]);
                }
            }
            sw1.Close();
        }
        static public void helpOverSampllingkBoxChecked(ref int[] classcounterArray, ref string[] vectorsfordup, string filename, string testName)
        {
            string path = @"C:\parkinsonTool\svm\" + testName + "\\" + filename;
            string[] lines = System.IO.File.ReadAllLines(path);
            string[] values;
            for (int h = 0; h < lines.Length; h++)
            {
                values = lines[h].Split(' ');
                if (numOfClasses == 3)
                {
                    switch(Convert.ToInt32(values[0]))
                    {
                        case 0:
                            classcounterArray[0]++;
                            break;
                        case 1:
                            classcounterArray[1]++;
                            break;

                        case 3:
                            classcounterArray[2]++;
                            break;
                    }
                }
                else
                {
                    classcounterArray[Convert.ToInt32(values[0])]++;
                }

                if (numOfClasses == 5)
                {
                    switch (Convert.ToInt32(values[0]))
                    {
                        case 0:
                            if (vectorsfordup[Convert.ToInt32(values[0])] == null)
                                vectorsfordup[Convert.ToInt32(values[0])] = lines[h];
                            break;
                        case 1:
                            if (vectorsfordup[Convert.ToInt32(values[0])] == null)
                                vectorsfordup[Convert.ToInt32(values[0])] = lines[h];
                            break;
                        case 2:
                            if (vectorsfordup[Convert.ToInt32(values[0])] == null)
                                vectorsfordup[Convert.ToInt32(values[0])] = lines[h];
                            break;
                        case 3:
                            if (vectorsfordup[Convert.ToInt32(values[0])] == null)
                                vectorsfordup[Convert.ToInt32(values[0])] = lines[h];
                            break;
                        case 4:
                            if (vectorsfordup[Convert.ToInt32(values[0])] == null)
                                vectorsfordup[Convert.ToInt32(values[0])] = lines[h];
                            break;
                    }
                }
                else if (numOfClasses == 3)
                {
                    switch (Convert.ToInt32(values[0]))
                    {
                        case 0:
                            if (vectorsfordup[0] == null)
                                vectorsfordup[0] = lines[h];
                            break;
                        case 1:
                            if (vectorsfordup[1] == null)
                                vectorsfordup[1] = lines[h];
                            break;
                        case 3:
                            if (vectorsfordup[2] == null)
                                vectorsfordup[2] = lines[h];
                            break;
                    }
                }
                


            } //end of for
        }
        static public void helpscalingCheckBoxChecked(ref objForgenerateRandomVectorFile obj1)
        {
            string path = @"C:\parkinsonTool\svm\finger Taps\\finger Taps_trainfile.train";
            TextWriter tw = new StreamWriter(@"C:\parkinsonTool\svm\finger Taps\scaleParams.csv");
            string[] lines = System.IO.File.ReadAllLines(path);
            string[] values;
            string[] inervalues;

            for (int h = 0; h < lines.Length; h++)
            {
                values = lines[h].Split(' ');
                for (int j = 1; j < values.Length - 2; j++)
                {
                    inervalues = values[j].Split(':');

                    if (obj1.fingerMaxArray[j - 1] < (float)Convert.ToDouble(inervalues[1]))
                        obj1.fingerMaxArray[j - 1] = (float)Convert.ToDouble(inervalues[1]);

                    if (obj1.fingerMinArray[j - 1] > (float)Convert.ToDouble(inervalues[1]))
                        obj1.fingerMinArray[j - 1] = (float)Convert.ToDouble(inervalues[1]);

                }
            } //end of for

            tw.WriteLine("max value for each class,");
            for (int i = 0; i < obj1.fingerMaxArray.Count(); i++)
            {
                tw.Write(i + "," + obj1.fingerMaxArray[i]);
                tw.WriteLine("");

            }
            tw.WriteLine("min value for each class,");
            for (int i = 0; i < obj1.fingerMinArray.Count(); i++)
            {
                tw.Write(i + "," + obj1.fingerMinArray[i]);
                tw.WriteLine("");
            }
            tw.Close();
            //======================================================================//

            path = @"C:\parkinsonTool\svm\hand Movements\\hand Movements_trainfile.train";
            lines = System.IO.File.ReadAllLines(path);
            tw = new StreamWriter(@"C:\parkinsonTool\svm\hand Movements\scaleParams.csv");

            for (int h = 0; h < lines.Length; h++)
            {
                values = lines[h].Split(' ');

                for (int j = 1; j < values.Length - 2; j++)
                {
                    inervalues = values[j].Split(':');

                    if (obj1.handMaxArray[j - 1] < (float)Convert.ToDouble(inervalues[1]))
                        obj1.handMaxArray[j - 1] = (float)Convert.ToDouble(inervalues[1]);

                    if (obj1.handMinArray[j - 1] > (float)Convert.ToDouble(inervalues[1]))
                        obj1.handMinArray[j - 1] = (float)Convert.ToDouble(inervalues[1]);

                }
            } //end of for

            tw.WriteLine("max value for each class,");
            for (int i = 0; i < obj1.handMaxArray.Count(); i++)
            {
                tw.Write(i + "," + obj1.handMaxArray[i]);
                tw.WriteLine("");
            }
            tw.WriteLine("min value for each class,");
            for (int i = 0; i < obj1.handMinArray.Count(); i++)
            {
                tw.Write(i + "," + obj1.handMinArray[i]);
                tw.WriteLine("");
            }
            tw.Close();
        }
        static public void createParamaterVector(string testName, string pathOfFile, ref List<float> vector1, ref objForgenerateRandomVectorFile obj2)
        {
            objectForRead objForRead = new objectForRead();
            objForRead.centerOfHandListForSaving = new List<CenterOfHandStruct>();
            objForRead.fingerTipsListForSaving = new List<FingerTipsStruct>();
            objForRead.path = pathOfFile;
            //loadDataFromExcel(ref objForRead); //loads the data from the excel file to the objForRead struct.
            FileMgr.loadDataFromText(ref objForRead); //loads the data from the text file to the objForRead struct.

            //******variables for calculations ********// 
            float openStartTime = -1, openEndTime = -1;
            float closeStartTime = -1, closeEndTime = -1;
            int openCounter = 0, closeCounter = 0;
            List<float> timeHandOpenList = new List<float>(); //for debuging 
            List<float> timeHandCloseList = new List<float>(); //for debuging 

            List<float> timeHandCloseDiferList = new List<float>(); //for debuging 
            List<float> timeHandOpenDiferList = new List<float>(); //for debuging 

            List<float> fingerRecognizedCounterList = new List<float>(); //for debuging 
            List<float> fingerRecognizedInOneActionCounterList = new List<float>(); //for debuging 
            float prevTime = 0;
            float curentTime = 0;
            float avgFingerCount = 0;
            float sumTimeHandOpen = 0, sumTimeHandClose = 0;
            int fingerRecognizedCounter = 0;
            int endOfCheck = 1;
            //*****************************************//

            foreach (FingerTipsStruct tempFingerTipStruct in objForRead.fingerTipsListForSaving)
            {

                if ((tempFingerTipStruct.X == -1) && (closeStartTime == -1))
                {
                    closeStartTime = (float)Convert.ToDouble(tempFingerTipStruct.timeStemp);
                    openEndTime = closeStartTime;
                    if (openStartTime != -1)
                    {
                        timeHandOpenList.Add(openEndTime - openStartTime); //for debuging
                        sumTimeHandOpen += (openEndTime - openStartTime);
                        if (fingerRecognizedInOneActionCounterList.Count != 0)
                        {
                            avgFingerCount = GeneralCalc.calcAvg(fingerRecognizedInOneActionCounterList); //the avg number of fingers recognized in one action (one openning of hand)
                            fingerRecognizedCounterList.Add(avgFingerCount); //for debuging
                        }
                        fingerRecognizedCounter = 0;
                        fingerRecognizedInOneActionCounterList.Clear();

                        openCounter++;
                    }
                }
                else if ((tempFingerTipStruct.X != -1) && (closeStartTime != -1))
                {
                    closeEndTime = (float)Convert.ToDouble(tempFingerTipStruct.timeStemp);
                    timeHandCloseList.Add(closeEndTime - closeStartTime); //for debuging
                    sumTimeHandClose += (closeEndTime - closeStartTime);
                    closeCounter++;
                    openStartTime = closeEndTime;
                    closeStartTime = -1;

                }
                else if ((tempFingerTipStruct.X != -1) && (openStartTime == -1))
                {
                    openStartTime = (float)Convert.ToDouble(tempFingerTipStruct.timeStemp);
                }

                if (tempFingerTipStruct.X != -1)
                {
                    curentTime = (float)Convert.ToDouble(tempFingerTipStruct.timeStemp);
                    if (prevTime == 0)
                    {
                        //fingerRecognizedCounter++;
                    }
                    else if (prevTime == curentTime)
                    {
                        fingerRecognizedCounter++;
                    }
                    else if (prevTime != curentTime)
                    {
                        endOfCheck = 0;
                        fingerRecognizedCounter++;
                    }

                    if (endOfCheck == 0)
                    {
                        fingerRecognizedInOneActionCounterList.Add(fingerRecognizedCounter);
                        fingerRecognizedCounter = 0;
                        endOfCheck = 1;
                    }

                    prevTime = curentTime;

                }
            }
            //------------------------extract parameter vector-----------------------------------//
            float[] featureVector;
            float difOpenMax ;
            float difCloseMax ;

            switch (testName)
            {
                case "finger Taps":
                case "Finger Taps":
                    featureVector = new float[fingerTaps_featureNumber];

                    featureVector[0] = GeneralCalc.calcRatio(sumTimeHandOpen, openCounter);//avgopen
                    featureVector[1] = GeneralCalc.calcRatio(sumTimeHandClose, closeCounter);//avgclose
                    featureVector[2] = GeneralCalc.calcRatio(featureVector[0], featureVector[1]);//ratio
                    featureVector[3] = GeneralCalc.calcSumDiviation(featureVector[0], timeHandOpenList);//diviationOpenHand_avgopen
                    featureVector[4] = GeneralCalc.calcSumDiviation(featureVector[1], timeHandCloseList);//diviationCloseHand_avgclose
                    featureVector[5] = GeneralCalc.calcAvg(fingerRecognizedCounterList);//avgFingerRecodnized
                    //featureVector[6] = GeneralCalc.calcKurtosis(featureVector[0], featureVector[3], timeHandOpenList); //kurtosis_openHand
                    //featureVector[7] = GeneralCalc.calcKurtosis(featureVector[1], featureVector[4], timeHandCloseList); //kurtosis_closeHand
                    //featureVector[8] = GeneralCalc.calcSkewness(featureVector[0], featureVector[3], timeHandOpenList); //skewness_openHand
                    //featureVector[9] = GeneralCalc.calcSkewness(featureVector[1], featureVector[4], timeHandCloseList); //skewness_closeHand



                    //-----used for checking data ---//
                    difOpenMax = 0;
                    difCloseMax = 0;
                    foreach (float number in timeHandOpenList)
                    {
                        float temp = (float)Math.Floor(number / featureVector[0]);
                        timeHandOpenDiferList.Add(temp);
                        if (difOpenMax < temp)
                            difOpenMax = temp;
                    }

                    foreach (float number in timeHandCloseList)
                    {
                        float temp = (float)Math.Floor(number / featureVector[1]);
                        timeHandCloseDiferList.Add((float)Math.Floor(temp));
                        if (difCloseMax < temp)
                            difCloseMax = temp;
                    }
                    featureVector[6] = Math.Max(difOpenMax, difCloseMax);//maxOfMax
                    //-------------------------------//

                    break;
                case "hand Movements":
                case "Hand Movements":
                    featureVector = new float[HandMovements_featureNumber];

                    featureVector[0] = GeneralCalc.calcRatio(sumTimeHandOpen, openCounter);//avgopen
                    featureVector[1] = GeneralCalc.calcRatio(sumTimeHandClose, closeCounter);//avgclose
                    featureVector[2] = GeneralCalc.calcRatio(featureVector[0], featureVector[1]);//ratio
                    featureVector[3] = GeneralCalc.calcSumDiviation(featureVector[0], timeHandOpenList);//diviationOpenHand_avgopen
                    featureVector[4] = GeneralCalc.calcSumDiviation(featureVector[1], timeHandCloseList);//diviationCloseHand_avgclose
                    featureVector[5] = GeneralCalc.calcAvg(fingerRecognizedCounterList);//avgFingerRecodnized
                    //featureVector[6] = GeneralCalc.calcKurtosis(featureVector[0], featureVector[3], timeHandOpenList); //kurtosis_openHand
                    //featureVector[7] = GeneralCalc.calcKurtosis(featureVector[1], featureVector[4], timeHandCloseList); //kurtosis_closeHand
                    //featureVector[8] = GeneralCalc.calcSkewness(featureVector[0], featureVector[3], timeHandOpenList); //skewness_openHand
                    //featureVector[9] = GeneralCalc.calcSkewness(featureVector[1], featureVector[4], timeHandCloseList); //skewness_closeHand



                    //-----used for checking data ---//
                    difOpenMax = 0;
                    difCloseMax = 0;
                    foreach (float number in timeHandOpenList)
                    {
                        float temp = (float)Math.Floor(number / featureVector[0]);
                        timeHandOpenDiferList.Add(temp);
                        if (difOpenMax < temp)
                            difOpenMax = temp;
                    }

                    foreach (float number in timeHandCloseList)
                    {
                        float temp = (float)Math.Floor(number / featureVector[1]);
                        timeHandCloseDiferList.Add((float)Math.Floor(temp));
                        if (difCloseMax < temp)
                            difCloseMax = temp;
                    }
                    //featureVector[10] = Math.Max(difOpenMax, difCloseMax);//maxOfMax
                    //-------------------------------//
                    break;

                default:
                    featureVector = new float[featureNumber];

                    featureVector[0] = GeneralCalc.calcRatio(sumTimeHandOpen, openCounter);//avgopen
                    featureVector[1] = GeneralCalc.calcRatio(sumTimeHandClose, closeCounter);//avgclose
                    featureVector[2] = GeneralCalc.calcRatio(featureVector[0], featureVector[1]);//ratio
                    featureVector[3] = GeneralCalc.calcSumDiviation(featureVector[0], timeHandOpenList);//diviationOpenHand_avgopen
                    featureVector[4] = GeneralCalc.calcSumDiviation(featureVector[1], timeHandCloseList);//diviationCloseHand_avgclose
                    featureVector[5] = GeneralCalc.calcAvg(fingerRecognizedCounterList);//avgFingerRecodnized
                    featureVector[6] = GeneralCalc.calcKurtosis(featureVector[0], featureVector[3], timeHandOpenList); //kurtosis_openHand
                    featureVector[7] = GeneralCalc.calcKurtosis(featureVector[1], featureVector[4], timeHandCloseList); //kurtosis_closeHand
                    featureVector[8] = GeneralCalc.calcSkewness(featureVector[0], featureVector[3], timeHandOpenList); //skewness_openHand
                    featureVector[9] = GeneralCalc.calcSkewness(featureVector[1], featureVector[4], timeHandCloseList); //skewness_closeHand



                    //-----used for checking data ---//
                    difOpenMax = 0;
                    difCloseMax = 0;
                    foreach (float number in timeHandOpenList)
                    {
                        float temp = (float)Math.Floor(number / featureVector[0]);
                        timeHandOpenDiferList.Add(temp);
                        if (difOpenMax < temp)
                            difOpenMax = temp;
                    }

                    foreach (float number in timeHandCloseList)
                    {
                        float temp = (float)Math.Floor(number / featureVector[1]);
                        timeHandCloseDiferList.Add((float)Math.Floor(temp));
                        if (difCloseMax < temp)
                            difCloseMax = temp;
                    }
                    featureVector[10] = Math.Max(difOpenMax, difCloseMax);//maxOfMax
                    //-------------------------------//
                    break;
            }//end of switch
            

            if (testName == "finger Taps" || testName == "Finger Taps")
            {
                if (obj2.fingerMaxArray[0] != -255) //scalling is checked
                {
                    for (int j = 0; j < featureVector.Count(); j++)
                    {
                        featureVector[j] = (featureVector[j] - obj2.fingerMinArray[j]) / obj2.fingerMaxArray[j];
                    }
                }
            }
            else if (testName == "hand Movements" || testName == "Hand Movements")
            {
                if (obj2.handMaxArray[0] != -255) //scalling is checked
                {
                    for (int j = 0; j < featureVector.Count(); j++)
                    {
                        featureVector[j] = (featureVector[j] - obj2.handMinArray[j]) / obj2.handMaxArray[j];
                    }
                }
            }


            int tempGrade = (int)Convert.ToDouble(objForRead.grade);
            //====================chnage classes to 3 insted of 4==================//
            if (numOfClasses == 3)
            switch (tempGrade)
            {
                case 0:
                    tempGrade = 0;
                    break;

                case 1:
                    tempGrade = 1;
                break;

                case 2:
                tempGrade = 1;
                break;

                case 3:
                tempGrade = 3;
                break;

                case 4:
                tempGrade = 3;
                break;
            }

            vector1.Add((float)tempGrade);
            //==================================================================//

            for (int j = 0; j < featureVector.Count(); j++)
            {
                vector1.Add(featureVector[j]); //create vector
            }
            //--------------------------------------------------------------------------------------//

        }
        static public void generateRandomVectorFilesWrapper(object obj1)
        {
            objForgenerateRandomVectorFile obj2 = (objForgenerateRandomVectorFile)obj1;

            generateRandomVectorFiles("finger Taps", obj2);
            generateRandomVectorFiles("hand Movements", obj2);
            if (obj2.index == -1)
            {
                MessageBox.Show("finished creating the train and predict files", "My Application", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }
        static public void generateRandomVectorFiles(string testName, objForgenerateRandomVectorFile obj2)
        {

            string FilePath = @"C:\parkinsonTool\rawData\training\" + testName;
            string[] dirNamesArry = System.IO.Directory.GetDirectories(FilePath); //get all the ID Directories
            List<string> predictList = new List<string>();
            List<string> trainList = new List<string>();

            if (obj2.index == -1) //leave one out vector seperation
            {
                for (int j = 0; j < dirNamesArry.Count(); j++)
                {
                    generateVectorFile(dirNamesArry[j], dirNamesArry, j.ToString(), testName, obj2);
                }
            }
            else // 30% predict , 70% train
            {
                List<int> result = GeneralCalc.generateRandomNumbers(dirNamesArry.Count(), 30, dirNamesArry.Count());

                for (int i = 0; i < dirNamesArry.Count(); i++)
                {
                    if (result.Exists(value => value == i))
                    {
                        predictList.Add(dirNamesArry[i]);
                    }
                    else
                    {
                        trainList.Add(dirNamesArry[i]);
                    }
                }
                generateVectorFile(trainList, "train" + obj2.index.ToString() + ".text", testName, obj2); //generate vector file for all the files in the choosen directories
                generateVectorFile(predictList, "predict" + obj2.index.ToString() + ".text", testName, obj2);
            }


        }
        static public void generateVectorFile(string dirOneOutName, string[] dirNamesArry, string vectorIndex, string testName, objForgenerateRandomVectorFile obj2)
        {
            string path = @"C:\parkinsonTool\svm\" + testName + "\\";
            string trainFileName = "train" + vectorIndex.ToString() + ".text";
            string predictFileName = "predict" + vectorIndex.ToString() + ".text";

            TextWriter tw = new StreamWriter(path + trainFileName);
            TextWriter pw = new StreamWriter(path + predictFileName);

            UTF8Encoding utf8 = new UTF8Encoding();
            string fileOutPut;
            string[] subfilesNamesArry;
            List<float> tempVector = new List<float>();

            foreach (string iterator in dirNamesArry) //train text file
            {
                if (iterator != dirOneOutName)
                {
                    subfilesNamesArry = System.IO.Directory.GetFiles(iterator, "*.text"); //get all the names of the text files

                    foreach (string tempfileName in subfilesNamesArry) //for each excel file do...
                    {
                        VectorOperations.createParamaterVector(testName, tempfileName, ref tempVector, ref obj2);
                        int index = 0;
                        foreach (float it in tempVector)
                        {
                            if (index == 0) //for writing the class 
                            {
                                fileOutPut = it + " ";
                                byte[] encodedBytes = utf8.GetBytes(fileOutPut);
                                tw.Write(utf8.GetString(encodedBytes));
                                index++;
                            }
                            else
                            {
                                fileOutPut = index + ":" + it + " ";
                                byte[] encodedBytes = utf8.GetBytes(fileOutPut);
                                tw.Write(utf8.GetString(encodedBytes));
                                index++;
                            }
                        }
                        tempVector.Clear();
                        tw.WriteLine(" ");

                    } //end of loop
                }

            } //end of loop

            // close the stream
            tw.Close();
            //======================================//

            //build predict text file
            subfilesNamesArry = System.IO.Directory.GetFiles(dirOneOutName, "*.text"); //get all the names of the excel files
            foreach (string tempfileName in subfilesNamesArry) //for each excel file do...
            {
                createParamaterVector(testName, tempfileName,ref tempVector,ref obj2);
                int index = 0;
                foreach (float it in tempVector)
                {
                    if (index == 0) //for writing the class 
                    {
                        fileOutPut = it + " ";
                        byte[] encodedBytes = utf8.GetBytes(fileOutPut);
                        pw.Write(utf8.GetString(encodedBytes));
                        index++;
                    }
                    else
                    {
                        fileOutPut = index + ":" + it + " ";
                        byte[] encodedBytes = utf8.GetBytes(fileOutPut);
                        pw.Write(utf8.GetString(encodedBytes));
                        index++;
                    }

                }
                tempVector.Clear();
                pw.WriteLine(" ");

            } //end of loop

            // close the stream
            pw.Close();
        }
        static public void generateVectorFile(List<string> dirNamesArry, string fileName, string testName, objForgenerateRandomVectorFile obj2)
        {
            string path = @"C:\parkinsonTool\svm\" + testName + "\\";
            TextWriter tw = new StreamWriter(path + fileName);
            UTF8Encoding utf8 = new UTF8Encoding();
            string fileOutPut;
            string[] subfilesNamesArry;

            List<float> vector1 = new List<float>();

            //for (int i = starIndex; i < endIndex; i++)// for each one of the choosen directories do...
            foreach (string iterator in dirNamesArry)
            {
                subfilesNamesArry = System.IO.Directory.GetFiles(iterator, "*.text"); //get all the names of the excel files
                foreach (string tempfileName in subfilesNamesArry) //for each excel file do...
                {
                    createParamaterVector(testName, tempfileName,ref vector1,ref obj2);
                    int index = 0;
                    foreach (float it in vector1)
                    {
                        if (index == 0) //for writing the class 
                        {
                            fileOutPut = it + " ";
                            byte[] encodedBytes = utf8.GetBytes(fileOutPut);
                            tw.Write(utf8.GetString(encodedBytes));
                            index++;
                        }
                        else
                        {
                            fileOutPut = index + ":" + it + " ";
                            byte[] encodedBytes = utf8.GetBytes(fileOutPut);
                            tw.Write(utf8.GetString(encodedBytes));
                            index++;
                        }

                    }
                    vector1.Clear();
                    tw.WriteLine(" ");

                }

            }
            // close the stream
            tw.Close();
        }
    
    }
}
